package com.nineclock.document.service.impl;

import cn.hutool.core.util.StrUtil;
import com.nineclock.common.enums.ResponseEnum;
import com.nineclock.common.exception.NcException;
import com.nineclock.common.threadlocal.CurrentUserHolder;
import com.nineclock.common.utils.BeanHelper;
import com.nineclock.document.dto.DocFolderDto;
import com.nineclock.document.mapper.DocFolderMapper;
import com.nineclock.document.pojo.DocFolder;
import com.nineclock.document.service.DocFolderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
@Transactional
public class DocFolderServiceImpl implements DocFolderService {

    @Autowired
    private DocFolderMapper folderMapper;

    @Override
    public void insertFolder(DocFolderDto folderDto) {
        //参数校验
        if(folderDto == null || StrUtil.isEmpty(folderDto.getName())){
            throw new NcException(ResponseEnum.INVALID_PARAM_ERROR);
        }

        //业务判定 ---> 文件夹的名字不重复


        //组装数据, 保存
        DocFolder docFolder = BeanHelper.copyProperties(folderDto, DocFolder.class);
        docFolder.setCompanyId(CurrentUserHolder.get().getCompanyId());
        docFolder.setCreateUserId(CurrentUserHolder.get().getCompanyUserId());
        docFolder.setStatus((short)1);
        docFolder.setOrderNum(0);
        docFolder.setCreateTime(new Date());

        folderMapper.insert(docFolder);
    }

}
